<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       
    </style>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="root"></div>
</body>
<script>
    // data & methods & computed & watcher
    const app = Vue.createApp({
        data(){
            return {
                show:true,
                list:['dell', 'apple', 'bonanana'],
                object:{firstName:'tom',lastName:'bill'},
                array:['林冲','晁盖','宋江'],
                ageArray:[17,18,15,38,39,59,21,12]
            }
        },
        methods:{
            // 使用数组的变更函数push, pop, shift, unshift，splice, sort
            add(){
                this.array.push('阮小五');
            },
            pop(){
                this.array.pop();
            },
            shift(){
                this.array.shift('shift');
            },
            unshift(){
                this.array.unshift('旁秋燕');
            },
            splice(){
                this.array.splice(2,2,'燕青');
            },
            filter(){
                this.ageArray = this.ageArray.filter(age => age>=18);
            }
        },
        template:
        `
           <div v-show="show">hello world</div>
           <div v-if="!show">nihaoshijie</div>
           <div v-else-if="show">nihaoshijie else if</div>
           <div v-else="!show">你好世界</div>
           <div v-for="(item, index) of list">{{item}}-{{index}}</div>
           <div v-for="(item, key, index) of object">{{item}}-{{key}}-{{index}}</div>
           <div v-for="(item, index) of array" :key="item">{{item}}-{{index}}
            <button @click="add">添加</button>
            <button @click="pop">减少</button>
            <button @click="shift">shift</button>
            <button @click="unshift">unshift</button>
            <button @click="splice">splice</button>
            </div>
            <div>年龄超过18岁的：<div v-for="item in ageArray">{{item}}</div><button @click="filter">filter</button></div>
        `
    });

    app.component('demo', {
        template: `
            
            
        `
    });

    const vm = app.mount("#root");
</script>
</html>